module("Filters testing");

test('does createFilter() return same predetermined filter', function() {
    var filter = new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.LIKE,
        property: 'pnr:kuntaKoodi',
        value: '564',
        wildCard: '*',
        matchCase: false
    });
    var filter2 = new Filters().createFilter('pnr:kuntaKoodi', '564');
    assert.deepEqual(filter, filter2, 'createFilter() returns predetermined filter');
});

test('does createAndFilter() return same predetermined andFilter', function() {
    var filter = new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.LIKE,
        property: 'pnr:kuntaKoodi',
        value: '564',
        wildCard: '*',
        matchCase: false
    });

    var filter2 = new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.LIKE,
        property: 'pnr:kirjoitusasu',
        value: 'Kumpula',
        wildCard: '*',
        matchCase: false
    });

    var and_filter = new OpenLayers.Filter.Logical({
        type: OpenLayers.Filter.Logical.AND,
        filters: [
            new OpenLayers.Filter.Comparison({
                type: OpenLayers.Filter.Comparison.LIKE,
                property: 'pnr:kuntaKoodi',
                value: '564',
                wildCard: '*',
                matchCase: false
            }),
            new OpenLayers.Filter.Comparison({
                type: OpenLayers.Filter.Comparison.LIKE,
                property: 'pnr:kirjoitusasu',
                value: 'Kumpula',
                wildCard: '*',
                matchCase: false
            })
        ]
    });

    var and_filter2 = new Filters().createAndFilter(filter, filter2);
    assert.deepEqual(and_filter, and_filter2, 'createAndFilter() returns predetermined andFilter');
});

test('does createOrFilter() return same predetermined orFilter', function() {
    var filter = new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.LIKE,
        property: 'pnr:kirjoitusasu',
        value: 'Hervanta',
        wildCard: '*',
        matchCase: false
    });

    var filter2 = new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.LIKE,
        property: 'pnr:kirjoitusasu',
        value: 'Kumpula',
        wildCard: '*',
        matchCase: false
    });

    var or_filter = new OpenLayers.Filter.Logical({
        type: OpenLayers.Filter.Logical.Or,
        filters: [
            new OpenLayers.Filter.Comparison({
                type: OpenLayers.Filter.Comparison.LIKE,
                property: 'pnr:kirjoitusasu',
                value: 'Hervanta',
                wildCard: '*',
                matchCase: false
            }),
            new OpenLayers.Filter.Comparison({
                type: OpenLayers.Filter.Comparison.LIKE,
                property: 'pnr:kirjoitusasu',
                value: 'Kumpula',
                wildCard: '*',
                matchCase: false
            })
        ],
        "type": "||"
    });

    var or_filter2 = new Filters().createOrFilter(filter, filter2);
    assert.deepEqual(or_filter, or_filter2, 'createOrFilter() returns predetermined orFilter');
});

test('does createRadialFilter() return same predetermined radialFilter', function() {
    var point = new OpenLayers.Geometry.Point(1,1);
    var filter = new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Spatial.DWITHIN,
        property: 'pnr:paikkaSijainti',
        value: point,
        distance: (100 * 1000),
        distanceUnits: 'm'
    });
    var filter2 = new Filters().createRadialFilter(point ,100);
    assert.deepEqual(filter, filter2, 'createRadialFilter() returns predetermined radialFilter');
});

test('does createBoundedFilter() return same predetermined boundedFilter', function() {
    var bounds = new OpenLayers.Bounds(1,2,2,1);
    var filter = new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Spatial.BBOX,
        property: 'pnr:paikkaSijainti',
        value: new OpenLayers.Bounds(1,2,2,1)
    });
    var filter2 = new Filters().createBoundedFilter(bounds);
    assert.deepEqual(filter, filter2, 'createBoundedFilter() returns predetermined boundedFilter');
});